capture program drop top1
program define top1

// Program that shows basic aggregates for each group (99/100)

args renta cuota	// gross income and tax liability

preserve

quiet{

gen rentaneta=`renta'-`cuota' // net income

foreach var in /*`renta'*/ rentaneta `cuota'{

nois disp ""
nois disp in red "`var'"

sum `var' if centila==100 [iw=factor]
local i100=r(sum)
sum `var' [iw=factor]
nois disp in green "Income_share " `i100'/r(sum)

ginis `var' [aw=factor] if centila<100
nois disp "Ginis_99 " %18.17g $ginis

ginis `var' [aw=factor] if centila==100
nois disp "Ginis_100 " %18.17g $ginis

ginis `var' [aw=factor]
nois disp "Gini_total " %18.17g $ginis

sum `var' if nivel==0 [iw=factor]
nois disp "Total_99_EUR " %20.0f r(sum)/100
sum `var' if nivel==1 [iw=factor]
nois disp "Total_100_EUR " %20.0f r(sum)/100

}

nois disp ""
sum factor if centila==100
local p100=r(sum)
sum factor
nois disp "Pop_share " `p100'/r(sum)

}

restore

end

/*
* Test
foreach type in cral_sty tax_new_133 tax_new_233 tax_new_333 tax_new_433 tax_new_533 tax_new_633 tax_new_733 tax_new_833 tax_new_933{
top1 gross_income `type'
}
*/
